Skip to content

Conversation

@bmchalenv
Copy link
Contributor

@bmchalenv bmchalenv commented Jan 14, 2026

Adds a pre-commit config that uses uncrustify and flake8 just like ament. ament isn't used directly since I wanted formatting to occur outside of a ROS environment when making small fixes. Also has other tools like whitespace, newline, copyright, yaml checks, code spelling, shell script formatting, and commit sign off checking.

Useful for fixing most issues with linting before it is pushed. Automatically reformats your commits, fixes copyright year issues, etc.

To run:

sudo apt install uncrustify pipx
pipx install pre-commit
pre-commit install --hook-type commit-msg --hook-type pre-commit
pre-commit run --all-files  # will also run on every commit now

NOTE: the sign-off check does not run in CI, only locally because it affects the commit message which is unchangeable at that point

@greptile-apps
Copy link

greptile-apps bot commented Jan 14, 2026

Greptile Overview

Greptile Summary

This PR introduces a comprehensive pre-commit configuration to automate code quality checks. The changes include adding pre-commit hooks for linting (flake8, uncrustify), formatting (autopep8, shfmt), copyright validation, YAML validation, whitespace cleanup, and spell checking. The PR also integrates these checks into the GitHub Actions CI workflow and documents the setup process in Contributing.md.

Key Changes:

  • Added .pre-commit-config.yaml with 10+ hooks for code quality enforcement
  • Integrated pre-commit checks into CI workflow (.github/workflows/ros-tests.yml)
  • Updated Contributing.md with installation and usage instructions
  • Applied automated formatting across the entire codebase (copyright year updates, trailing newlines, shell script indentation)
  • All previous syntax issues mentioned in review threads have been resolved

Impact:

  • Automated code quality enforcement before commits reach CI
  • Consistent code formatting across Python, C++, and shell scripts
  • Reduced manual review burden for style and formatting issues
  • Better developer experience with automatic fixes for common issues

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The PR adds tooling infrastructure without modifying core functionality. All formatting changes are automated and reversible. The pre-commit configuration is well-structured, uses standard tools (flake8, autopep8, uncrustify), and properly excludes build artifacts. CI integration ensures checks run on all PRs. Previous syntax issues have been resolved.
  • No files require special attention

Important Files Changed

Filename Overview
.pre-commit-config.yaml Adds comprehensive pre-commit configuration with linting, formatting, copyright checks, and code quality tools
.github/workflows/ros-tests.yml Adds pre-commit job to CI workflow with proper dependency installation
Contributing.md Documents pre-commit setup instructions and uninstall command
greenwave_monitor_interfaces/package.xml Adds copyright header (properly formatted with XML comment syntax, not duplicate declaration)
scripts/docker-test.sh Reformats shell script with consistent indentation (tabs instead of spaces), updates copyright year
scripts/build_debian_packages.sh Reformats shell script with consistent indentation, updates copyright year

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant Git as Git Commit
    participant PreCommit as Pre-commit Framework
    participant Hooks as Pre-commit Hooks
    participant CI as GitHub Actions

    Dev->>Git: git commit -s -m "message"
    Git->>PreCommit: Trigger pre-commit hooks
    
    PreCommit->>Hooks: check-yaml
    Hooks-->>PreCommit: ✓ YAML files valid
    
    PreCommit->>Hooks: end-of-file-fixer
    Hooks-->>PreCommit: ✓ Fixed missing newlines
    
    PreCommit->>Hooks: trailing-whitespace
    Hooks-->>PreCommit: ✓ Removed trailing whitespace
    
    PreCommit->>Hooks: autopep8 (Python formatting)
    Hooks-->>PreCommit: ✓ Python code formatted
    
    PreCommit->>Hooks: flake8 (Python linting)
    Hooks-->>PreCommit: ✓ Python code passes linting
    
    PreCommit->>Hooks: shfmt (Shell formatting)
    Hooks-->>PreCommit: ✓ Shell scripts formatted
    
    PreCommit->>Hooks: copyright-required
    Hooks-->>PreCommit: ✓ Copyright headers present
    
    PreCommit->>Hooks: uncrustify (C/C++ formatting)
    Hooks-->>PreCommit: ✓ C/C++ code formatted
    
    PreCommit->>Hooks: codespell (Spelling check)
    Hooks-->>PreCommit: ✓ No spelling errors
    
    Git->>PreCommit: Trigger commit-msg hook
    PreCommit->>Hooks: signed-off-by check
    Hooks-->>PreCommit: ✓ Commit is signed off
    
    PreCommit-->>Git: All checks passed
    Git-->>Dev: Commit created
    
    Dev->>CI: Push to GitHub
    CI->>CI: Checkout code
    CI->>CI: Install uncrustify + dependencies
    CI->>PreCommit: Run pre-commit on all files
    PreCommit->>Hooks: Execute all hooks
    Hooks-->>PreCommit: ✓ All checks passed
    PreCommit-->>CI: Success
    CI-->>Dev: ✓ CI passed
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

23 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

23 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

23 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment on lines 179 to 183
should_redraw = (
key != -
1) or (
current_time -
last_redraw >= redraw_interval)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Autopep8 broke this expression by splitting -1 across lines. key != - on one line and 1) on the next is incorrect formatting.

Suggested change
should_redraw = (
key != -
1) or (
current_time -
last_redraw >= redraw_interval)
should_redraw = (key != -1) or (current_time - last_redraw >= redraw_interval)

Comment on lines 211 to 217
header = (
f'{
"Topic Name":<{MAX_NAME_WIDTH}} {
"Status":<{STATUS_WIDTH}} ' f'{
"Pub Rate (Hz)":<{FRAME_RATE_WIDTH}} ' f'{
"Latency (ms)":<{REALTIME_DELAY_WIDTH}} {
"Expected Hz":<12}')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: F-string formatting is broken. Line breaks inside the f-string placeholders create invalid syntax.

Suggested change
header = (
f'{
"Topic Name":<{MAX_NAME_WIDTH}} {
"Status":<{STATUS_WIDTH}} ' f'{
"Pub Rate (Hz)":<{FRAME_RATE_WIDTH}} ' f'{
"Latency (ms)":<{REALTIME_DELAY_WIDTH}} {
"Expected Hz":<12}')
header = (f'{"Topic Name":<{MAX_NAME_WIDTH}} {"Status":<{STATUS_WIDTH}} '
f'{"Pub Rate (Hz)":<{FRAME_RATE_WIDTH}} '
f'{"Latency (ms)":<{REALTIME_DELAY_WIDTH}} {"Expected Hz":<12}')

Comment on lines 87 to 89
topic_set = {
topic_name for topic_name,
topic_type in topic_names_and_types}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Set comprehension incorrectly split. The comma between topic_name and topic_type should be on the same line.

Suggested change
topic_set = {
topic_name for topic_name,
topic_type in topic_names_and_types}
topic_set = {topic_name for topic_name, topic_type in topic_names_and_types}

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines 26 to 27
- id: autopep8
args: [-i, -a, -a]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The -a -a flags make autopep8 very aggressive, causing the broken formatting in ncurses_frontend.py. Consider using just -i or single -a to avoid overly aggressive line breaking.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines 58 to 67
- name: Run pre-commit hooks (linting, sign-off check, copyright check, etc.)
run: |
apt update && apt install -y pipx git
pipx install pre-commit
pipx ensurepath
source ~/.bashrc
pre-commit run --all-files --show-diff-on-failure
shell: bash
working-directory: greenwave_monitor
env:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-commit runs in wrong directory. Code is checked out to greenwave_monitor/ subdirectory (line 56) but this step doesn't cd into it before running pre-commit.

Suggested change
- name: Run pre-commit hooks (linting, sign-off check, copyright check, etc.)
run: |
apt update && apt install -y pipx git
pipx install pre-commit
pipx ensurepath
source ~/.bashrc
pre-commit run --all-files --show-diff-on-failure
shell: bash
working-directory: greenwave_monitor
env:
- name: Run pre-commit hooks (linting, sign-off check, copyright check, etc.)
run: |
cd greenwave_monitor
apt update && apt install -y pipx git
pipx install pre-commit
pipx ensurepath
source ~/.bashrc
pre-commit run --all-files --show-diff-on-failure
shell: bash
env:
DEBIAN_FRONTEND: noninteractive


- name: Run pre-commit hooks (linting, sign-off check, copyright check, etc.)
run: |
apt update && apt install -y pipx git
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uncrustify dependency missing. Pre-commit config uses uncrustify (line 46 of .pre-commit-config.yaml) but it's not installed here. Contributing.md also mentions it's required.

Suggested change
apt update && apt install -y pipx git
apt update && apt install -y pipx git uncrustify

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile


- name: Run pre-commit hooks (linting, sign-off check, copyright check, etc.)
run: |
apt update && apt install -y pipx git
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uncrustify is required by the pre-commit config (line 46 of .pre-commit-config.yaml) but isn't installed here. Add it to the apt install command.

Suggested change
apt update && apt install -y pipx git
apt update && apt install -y pipx git uncrustify

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@sgillen
Copy link
Collaborator

sgillen commented Jan 28, 2026

Looks good, thanks! Can you please update the Contributing.md to account for the fact that signing is done automatically, and include the apt install and pipx commands there as well.

@bmchalenv
Copy link
Contributor Author

bmchalenv commented Jan 28, 2026

Looks good, thanks! Can you please update the Contributing.md to account for the fact that signing is done automatically, and include the apt install and pipx commands there as well.

That's already done here. Also signing is not done automatically it just errors if you haven't signed. Usual philosophy with sign-offs is you have to actively acknowledge that it is your own work so I kept that same idea.

@sgillen sgillen merged commit 022fedf into NVIDIA-ISAAC-ROS:main Jan 28, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants